﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CommunityToolkitMvvmDemo.UserControls
{
    /// <summary>
    /// MenuButton.xaml 的交互逻辑
    /// </summary>
    public partial class MenuButton : UserControl
    {
        private SolidColorBrush selectBackground = new SolidColorBrush(Color.FromRgb(31, 37, 35));
        private SolidColorBrush enterBackground = new SolidColorBrush(Color.FromRgb(48, 56, 59));
        private PathGeometry pathGeometry = new PathGeometry();
        private GeometryDrawing geometryDrawing = new GeometryDrawing();

        public MenuButton()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 按钮文本
        /// </summary>
        public string Content555
        {
            get { return (string)GetValue(Content555Property); }
            set { SetValue(Content555Property, value); }
        }
        public static readonly DependencyProperty Content555Property = DependencyProperty.Register("Content555",
                                                                                                                                                                     typeof(string),
                                                                                                                                                                     typeof(MenuButton),
                                                                                                                                                                     new PropertyMetadata("555", new PropertyChangedCallback(ContentPropertyChangedCallback)));
        private static void ContentPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (!(d is MenuButton source)) return;
            if (!(e.NewValue is string content)) return;

            source._textBlock.Text = content;
        }

        /// <summary>
        /// 前景色
        /// </summary>
        public Brush Foreground99
        {
            get { return (Brush)GetValue(Foreground99Property); }
            set { SetValue(Foreground99Property, value); }
        }
        public static readonly DependencyProperty Foreground99Property = DependencyProperty.Register("Foreground99",
                                                                                                                                                                         typeof(Brush),
                                                                                                                                                                         typeof(MenuButton),
                                                                                                                                                                         new PropertyMetadata(new SolidColorBrush(Color.FromRgb(102, 109, 115)), new PropertyChangedCallback(ForegroundPropertyChangedCallback)));
        private static void ForegroundPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (!(d is MenuButton source)) return;
            if (!(e.NewValue is Brush brush)) return;

            source.geometryDrawing.Brush = brush; // 设置图标颜色
            source._textBlock.Foreground = brush;    // 设置文字颜色
        }

        /// <summary>
        /// 背景色
        /// </summary>
        public new Brush Background
        {
            get { return (Brush)GetValue(BackgroundProperty); }
            set { SetValue(BackgroundProperty, value); }
        }
        public static new readonly DependencyProperty BackgroundProperty = DependencyProperty.Register("Background",
                                                                                                                                                                              typeof(Brush),
                                                                                                                                                                              typeof(MenuButton),
                                                                                                                                                                              new PropertyMetadata(null, new PropertyChangedCallback(BackgroundPropertyChangedCallback)));
        private static void BackgroundPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (!(d is MenuButton source)) return;
            if (!(e.NewValue is Brush brush)) return;

            source._contaier.Background = brush;
        }

        /// <summary>
        /// Path路径集合
        /// </summary>
        public PathFigureCollection PathFigures33
        {
            get { return (PathFigureCollection)GetValue(PathFigures33Property); }
            set { SetValue(PathFigures33Property, value); }
        }
        public static readonly DependencyProperty PathFigures33Property = DependencyProperty.Register("PathFigures33",
                                                                                                                                                                         typeof(PathFigureCollection),
                                                                                                                                                                         typeof(MenuButton),
                                                                                                                                                                         new PropertyMetadata(null, new PropertyChangedCallback(PathFiguresPropertyChangedCallback)));
        private static void PathFiguresPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (!(d is MenuButton source)) return;
            if (!(e.NewValue is PathFigureCollection figure)) return;

            source.pathGeometry.Figures = figure;
            source.geometryDrawing.Geometry = source.pathGeometry;
            source.geometryDrawing.Brush = source.Foreground;
            source._image.Source = new DrawingImage(source.geometryDrawing);
        }

    }
}
